<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class GroupListOrder extends Model
{
    //定义一个表名
    protected $table = 'group_list_order';
    //定义主键
    protected $primaryKey = 'id';
    protected $guarded = [];

    //生成订单号
    public static function make_no_g()
    {
        // 订单流水号前缀
        $prefix = "B".date('YmdHis');
        for ($i = 0; $i < 10; $i++) {
            // 随机生成 6 位的数字
            $no = $prefix.str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
            // 判断是否已经存在
            if (!empty(self::where('sn',$no)->first())) {
                $no = self::make_no();
            }
        }
        return $no;
    }
    
    //获取时间
    function getPaytypenameAttribute(){
        $paytype = ['1'=>'现金','2'=>"货款",'3'=>'支付宝','4'=>"微信"];
        return $paytype[$this->paytype];
    }

    //图片
    function getPicAttribute(){
        $picname = GroupList::where('id',$this->gid)->value('picname');
        return $picname;
    }

    //规格
    function getSkuAttribute(){
        $sku = GroupList::where('id',$this->gid)->value('attr');
        if($sku){
            return $sku;
        }else{
            return '无';
        }
    }

   
}
